package com.wavehi.dao.impl;

import com.wavehi.dao.BaseDao;
import com.wavehi.dao.IStaffDao;
import com.wavehi.pojo.Staff;

import java.util.List;

/**
 * @Author WaveHi
 * @Date 2/9/2021 下午 9:39
 * @Version 1.0
 * @Contact HJBWaveHi@163.com
 * @Description
 */
public class StaffDaoImpl extends BaseDao implements IStaffDao {
    @Override
    public void add(Staff staff) {
        String sql = "insert into t_staff(s_name,s_phone) values(?,?)";
        update(sql,staff.getName(),staff.getPhone());
    }

    @Override
    public void update(Staff staff) {
        String sql = "update t_staff set s_name=?,s_phone=? where s_id=?";
        update(sql,staff.getName(),staff.getPhone(),staff.getId());
    }

    @Override
    public void delete(Integer id) {
        String sql = "delete from t_staff where s_id=?";
        update(sql,id);
    }

    @Override
    public Staff select(String name) {
        String sql = "select s_id id,s_name name,s_phone phone from t_staff where s_name=?";
        return selectForOne(Staff.class,sql,name);
    }

    @Override
    public List<Staff> list() {
        String sql = "select s_id id,s_name name,s_phone phone from t_staff";
        return selectForList(Staff.class,sql);
    }
}
